package com.demo.shardingsphere5.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.shardingsphere5.dao.domain.UserSharding;
import com.demo.shardingsphere5.dao.mapper.UserShardingMapper;
import com.demo.shardingsphere5.service.UserShardingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* 同库分表策略
*/
@Service
public class UserShardingServiceImpl extends ServiceImpl<UserShardingMapper, UserSharding>
    implements UserShardingService{

    @Resource
    private UserShardingMapper userShardingMapper;

    public void insert(Long userId) {
        UserSharding user = new UserSharding();
        user.setUserName("aaa");
        user.setUserId(userId);

        super.save(user);
    }

    public UserSharding queryByUserId(Long userId) {
        return super.lambdaQuery().eq(UserSharding::getUserId, userId).one();
    }

    public UserSharding queryUsesrSharding0ByUserId(Long userId) {
        return userShardingMapper.queryUserSharding0ByUserId(userId);
    }
}




